package com.umeox.watch.moto.settings.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.Log;

/**
 * Created by Rambo 2019-12-26
 * Describe:
 */
public class AppUtils {

    /*
     *Function:判断指定包名的程序是否存在
     */
    public static boolean isApkExist(Context ctx, String packageName) {
        PackageManager pm = ctx.getPackageManager();
        PackageInfo packageInfo = null;
        String versionName = null;
        try {
            packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
            versionName = packageInfo.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            Log.e("FotaUpdate", "isApkExist not found");
            return false;
        }
        if (versionName != null) {
            String[] names = versionName.split("\\.");
            if (names.length >= 4 && ("9".equals(names[3]) || "9".equals(names[2]))) {
                return false;
            }
        }
        Log.i("FotaUpdate", "isApkExist = true");
        return true;
    }
}
